use crate::dto;
use crate::http::client::{error, rpc};
use crate::http::route;
use reqwest::Method;
use std::sync::Arc;

pub struct EndpointPeerClient {
    inner: Arc<rpc::Client>,
}

impl EndpointPeerClient {
    pub fn new(rpc_client: Arc<rpc::Client>) -> Self {
        Self { inner: rpc_client }
    }

    pub async fn add(
        &self,
        request: &dto::endpoint_peer::action::AddRequest,
    ) -> Result<dto::core::endpoint_peer::action::AddResponseData, error::Error> {
        self.inner
            .call(
                route::PATH_ENDPOINT_PEER_ADD,
                Method::POST,
                request,
                rpc::CallOptions::default(),
            )
            .await
    }

    pub async fn list(
        &self,
        request: &dto::endpoint_peer::action::ListRequest,
    ) -> Result<dto::endpoint_peer::action::ListResponseData, error::Error> {
        self.inner
            .call(
                route::PATH_ENDPOINT_PEER_LIST,
                Method::POST,
                request,
                rpc::CallOptions::default(),
            )
            .await
    }

    pub async fn get(
        &self,
        request: &dto::endpoint_peer::action::GetRequest,
    ) -> Result<dto::core::endpoint_peer::EndpointPeer, error::Error> {
        self.inner
            .call(
                route::PATH_ENDPOINT_PEER_GET,
                Method::POST,
                request,
                rpc::CallOptions::default(),
            )
            .await
    }

    pub async fn delete(
        &self,
        request: &dto::endpoint_peer::action::DeleteRequest,
    ) -> Result<(), error::Error> {
        self.inner
            .call(
                route::PATH_ENDPOINT_PEER_DELETE,
                Method::POST,
                request,
                rpc::CallOptions::default(),
            )
            .await
    }
}
